#ifndef __SYS_BUTTON_H
#define __SYS_BUTTON_H

#include "Sys.h"

typedef enum
{
    SYS_BUTTON_EVENT_LEVEL_FLIP = 0,
    SYS_BUTTON_EVENT_LONG_PRESS
} SysButtonEvent_t;

typedef void (*SysButtonHandle_t)(SysButtonEvent_t evt, uint8_t id, uint8_t io, uint8_t level);

typedef struct
{
    bool enable;
    uint8_t triggerLevel;
    uint32_t triggerInterval;
    uint32_t lastTriggerTime;
} SysButtonLongPress_t;

typedef struct
{
    bool enable;
    uint8_t io;
    bool flipping;
    uint8_t lastLevel;
    uint32_t jitterTime;
    SysButtonHandle_t handle;
    SysButtonLongPress_t longpress;
} SysButton_t;

uint8_t SysButtonGetLevel(uint8_t id);
int SysButtonLongpressSet(uint8_t id, uint8_t level, uint32_t interval);
int SysButtonRegister(uint8_t id, uint8_t io, SysButtonHandle_t handle);
void SysButtonInitialize(void);
void SysButtonPoll(void);

#endif
